package com.sanpu.kxe.business.main.view;

import android.content.Context;
import android.text.TextUtils;
import android.widget.TextView;

import com.sanpu.kxe.R;
import com.sanpu.kxe.base.BaseTitleActivity;
import com.sanpu.kxe.business.main.bean.NoticeOutput;
import com.sanpu.kxe.business.main.contract.MainConfig;
import com.sanpu.kxe.business.main.contract.NoticeDetailsContract;
import com.sanpu.kxe.business.main.presenter.NoticeDetailsPresenter;

import butterknife.Bind;

/**
 * Description：消息详情
 * Created by 薛勇军 on 2018/7/23.
 */

public class NoticeDetailsActivity extends BaseTitleActivity implements NoticeDetailsContract.View {

    @Bind(R.id.title)
    TextView vTitle;
    @Bind(R.id.date)
    TextView vDate;
    @Bind(R.id.des)
    TextView vDes;

    private NoticeDetailsContract.Presenter mPresenter;

    @Override
    protected int getLayoutResID() {
        return R.layout.activity_notice_details;
    }

    @Override
    protected void initView() {
        super.initView();
        commonTitle.setTitle("我的消息");

        mPresenter = new NoticeDetailsPresenter(this);
        boolean isMarquee = getIntent().getBooleanExtra(MainConfig.INTENT_ISMARQUEE, false);
        NoticeOutput mOutput = (NoticeOutput) getIntent().getSerializableExtra(MainConfig.INTENT_NOTICE);
        if (mOutput != null) {
            if (isMarquee) {
                mPresenter.messageDetail(mOutput.getId());
            } else {
                showDataView(mOutput);
            }
        }
    }

    @Override
    public void showDataView(NoticeOutput mOutput) {
        if (mOutput != null) {
            if (!TextUtils.isEmpty(mOutput.getTitle())) {
                vTitle.setText(mOutput.getTitle());
            }
            if (!TextUtils.isEmpty(mOutput.getGenerateTime())) {
                vDate.setText(mOutput.getGenerateTime());
            }
            if (!TextUtils.isEmpty(mOutput.getDetail())) {
                vDes.setText(mOutput.getDetail());
            }

            if (!mOutput.isMsgRead()) {
                mPresenter.markMessageRead(mOutput.getId());
            }
        }
    }

    @Override
    protected boolean hasBindEventBus() {
        return false;
    }

    @Override
    public void setPresenter(NoticeDetailsContract.Presenter presenter) {
        this.mPresenter = presenter;
    }

    @Override
    public Context getContext() {
        return this;
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (mPresenter != null) {
            mPresenter.onDestroyPresenter();
            mPresenter = null;
        }
    }
}
